home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 7228 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: qualcomm.com!usenet
  2. From: nabbasi@qualcomm.com (Nasser Abbasi)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Why Do Return Values Sometimes Have '&' Appended?
  5. Date: 22 Feb 1996 06:53:31 GMT
  6. Organization: QUalcomm Inc.
  7. Message-ID: <4gh3tb$l7n@qualcomm.com>
  8. References: <4ggciv$iq1@alcor.usc.edu>
  9. Reply-To: x!news.be.innet.net!INbe.net!usenet
  10. NNTP-Posting-Host: annex-p32.qualcomm.com
  11. X-Newsreader: WinVN 0.90.4
  12.  
  13. In article <4ggciv$iq1@alcor.usc.edu>, wawda@alcor.usc.edu (Abu Wawda) says:
  14. >
  15. >I have seen code where some of the functions are returned with the
  16. >reference operator (&) attached to the end. Here is an example:
  17. >
  18. >MyReturn& MyFunction(...)
  19. >{
  20. >}
  21. >
  22. >I don't understand what that does.
  23.  
  24. A reference is a name for an object. so returning a refernce means
  25. we are returning a name for an object that sits somewhere of type
  26. MyReturn. So, you need to ask where is this object?
  27.  
  28. One possibility is that MyFunction internally has a hidden static
  29. object of type MyReturn that processing is done on, then finaly
  30. a reference to it is returned. 
  31.  
  32. Or it is possible that inside MyFunction an object is created on the
  33. heap and a refernce is returned to it, but this can lead to memory 
  34. leak, since client of MyFunction need to figure how to delete this object.
  35. Plus one do not gain much by this method compared to by just returning
  36. the object.
  37.  
  38. Nasser
  39.  
  40.  
  41.